package respone

import (
	"express/pkg/time"
	"gorm.io/gorm"
)

type ExpressNumbers struct {
	Id     int    `gorm:"primary_key" json:"id"`
	UserId int    `label:"用户id"`
	Number string `label:"快递单号"`
	Status int    `label:"1为已发出"`
}

type ExpressNumber struct {
	Id         int           `gorm:"primary_key" json:"id"`
	UserId     int           `label:"用户id" json:"user_id"`
	Number     string        `label:"快递单号" json:"number"`
	Status     int           `label:"1为已发出" gorm:"default:1" json:"status"`
	StatusName string        `json:"status_name" gorm:"-"`
	NumNums    []NumNum      `gorm:"ForeignKey:ExpressId" json:"num_nums"`
	CreatedAt  time.JSONTime `json:"created_at"`
	UpdatedAt  time.JSONTime `json:"updated_at"`
}

func (e *ExpressNumber) AfterFind(*gorm.DB) (err error) {
	if e.Status == 1 {
		e.StatusName = "未寄出"
	} else if e.Status == 2 {
		e.StatusName = "已寄出"
	} else {
		e.StatusName = "未知"
	}
	return
}

type NumNum struct {
	Id        int    `gorm:"primary_key" json:"id"`
	ExpressId int    `label:"关联id" json:"express_id"`
	Sss       string `json:"sss"`
}

type Users struct {
	Id             int             `gorm:"primary_key" json:"id"`
	Phone          string          `label:"手机号"  gorm:"type:varchar(11);not null;default:''" json:"phone"`
	ExpressNumbers []ExpressNumber `gorm:"ForeignKey:user_id" json:"express_numbers"`
}
